package com.xlh.dokka.svc.core.scheduler.filter;


import com.xlh.dokka.svc.core.model.ContainerConfig;
import com.xlh.dokka.svc.core.model.GpuNode;
import com.xlh.dokka.svc.core.model.Node;
import org.apache.commons.collections.CollectionUtils;

import java.util.List;

/**
 * @author cheer
 */
public interface Filter {

    List<Node> filter(ContainerConfig config, List<Node> nodes);

    List<GpuNode> gpuFilter(ContainerConfig config, List<GpuNode> gpuNodes);

    static List<Node> applyFilters(List<Filter> filters, ContainerConfig config, List<Node> nodes) {
        List<Node> candidates = nodes;
        if (CollectionUtils.isNotEmpty(filters)) {
            for (Filter filter : filters) {
                candidates = filter.filter(config, candidates);
            }
        }
        return candidates;
    }

    static List<GpuNode> applyGpuFilters(List<Filter> filters, ContainerConfig config, List<GpuNode> gpuNodes) {
        List<GpuNode> candidates = gpuNodes;
        if (CollectionUtils.isNotEmpty(filters)) {
            for (Filter filter : filters) {
                candidates = filter.gpuFilter(config, candidates);
            }
        }
        return candidates;
    }
}
